<?php
/*
 * @author eBIZ Team <dev@jungo.com.cn>
 * @copyright  Copyright (c) , ShenZhen JunGO Technology Co., Ltd. All rights reserved.
 * @license  Commercial authorization, unauthorized use and modification are prohibited
 * @url www.jungo.com.cn
 */

namespace ckeeper\dao;


use ckeeper\db\DbHandler;
use ckeeper\db\Model;
use ckeeper\entity\RoleEntity;
use Selibra\Di\Annotations\Autowired;
use Selibra\ORM\Annotations\Entity;
use Selibra\ORM\Annotations\Table;

#[Table('manager_role')]
#[Entity(RoleEntity::class)]
class RoleDao extends Model
{

    /**
     * @param array $ids
     * @return RoleEntity[]|null
     */
    public function selectRolesByIds(array $ids)
    {
        $this->getCondition()->andWhere('id', 'in', implode(',', $ids));
        return $this->select();
    }


    /**
     * 添加角色
     * @param RoleEntity $roleEntity
     * @return mixed
     * @throws \Selibra\Model\Exception\DbException
     */
    public function addRole(RoleEntity $roleEntity)
    {
        return $this->insertGetId($roleEntity);
    }


    /**
     * 修改数据
     * @param int $id
     * @param string $key
     * @param string $value
     * @return array|bool
     * @throws \Selibra\Model\Exception\DbException
     */
    public function updateDataByField(int $id, string $key, string $value)
    {
        $this->getCondition()->andWhere('id', '=', $id);
        return $this->update([
            $key => $value
        ]);
    }


    /**
     * 修改数据
     * @param int $id
     * @param RoleEntity $roleEntity
     * @return array|bool
     * @throws \Selibra\Model\Exception\DbException
     */
    public function updateData(int $id,RoleEntity $roleEntity)
    {
        $this->getCondition()->andWhere('id', '=', $id);
        return $this->update($roleEntity);
    }

}
